package com.xiguthings.waka.web.listener;

import com.xiguthings.waka.publicUtils.SpringContextUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class SpringLoaderListener implements ServletContextListener {

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		Logger logger = LoggerFactory.getLogger(SpringLoaderListener.class);
//		Logger log = Logger.getLogger(SpringLoaderListener.class);
		logger.info("服务器启动成功！开始数据初始化。。。");
		ServletContext context = sce.getServletContext();
		WebApplicationContext webContext = WebApplicationContextUtils.getWebApplicationContext(context);
		SpringContextUtil.setApplicationContextStaticlly(webContext);
	}


	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		// TODO Auto-generated method stub

	}

}
